-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Planar Clarity Video Wall #65
base: master
Are you sure you want to change the base?
Conversation
Having a quick read now. To provide some further reading on TL;DR it can be used as a continent way to forward an arbitrary set of keyword arguments around. It was used a lot in the previous Ruby drivers, but would recommend avoiding it unless absolutely needed here as it can lead to some sloppy type signatures. |
@@ -0,0 +1,10 @@ | |||
DriverSpecs.mock_driver "Planar::ClarityMatrix" do | |||
# on connect it should do_poll the device | |||
should_send("op A1 display.power ? \r") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When writing specs, you also want to mock mock the device responses so that you test full request -> response behaviour. For some info on this, see: https://github.com/PlaceOS/drivers/blob/master/docs/writing-a-spec.md#testing-streaming-io.
Hi @kimburgess , upon going through this comment I thought it'd be a good idea to implement
and queue's method is defined in
which disallows anything but splats and NamedTuple in the argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had a look through and have picked up some things on style/feedback that @kimburgess has given me previously. There are probably other things I have missed or not knowledgable enough to give feedback on so best to reach out to @kimburgess for further feedback but this should hopefully be a good start of some things to look out for :)
drivers/planar/clarity_matrix.cr
Outdated
|
||
protected def do_poll | ||
power? | ||
input_status if self["power"] == "ON" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self[:power]
will be of type JSON::Any
so this should be changed to:
input_status if self[:power]?&.try as_bool
I've noticed this is necessary in order to use self values that are of type Bool
properly in conditional statements.
Explanation of why this is needed is here #19 (comment) and is probably to do with how crystal deals with truthy/falsy values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self[:key]
will return an error if the key does not exist while self[:key]?
will return nil so is safer to use generally.
.try
is a safe way to deal with objects that may be nil https://crystal-lang.org/api/0.35.1/Object.html#try(&)-instance-method
as_bool https://crystal-lang.org/api/0.19.4/JSON/Any.html#as_bool%3ABool-instance-method is necessary in order to convert self[:power]
which is of type JSON::Any
to type Bool
so it behaves as expected in conditional statements
drivers/planar/clarity_matrix.cr
Outdated
send "op ** slot.recall #{preset} \r", name: :recall | ||
end | ||
|
||
def input_status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be renamed to input?
to keep it consistent with power?
but @kimburgess can probably better comment on this
First attempt
Resolves #59
some confusion with options / **options